package com.kly.chatter.db.dao.impl;
import com.fqgj.common.api.Page;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.utils.CollectionUtils;
import com.google.common.collect.Maps;
import com.kly.chatter.db.dao.ChatterRewardInfoDao;
import com.kly.chatter.db.entity.ChatterRewardInfoEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* User: linqu
* Date: 2023-10-14
* Time: 21:46:18.387
*/

@Repository
public class ChatterRewardInfoDaoImpl extends AbstractBaseMapper<ChatterRewardInfoEntity> implements ChatterRewardInfoDao {

    @Override
    public List<ChatterRewardInfoEntity> listChatterRewardInfoToday() {
        return this.getSqlSession().selectList(this.getStatement("listChatterRewardInfoToday"));
    }

    @Override
    public List<ChatterRewardInfoEntity> listChatterRewardInfo(String chatterAccount, String chatterNickName, Date startDate, Date endDate, Page page, List<String> chatters) {
        Map<String, Object> params = setupQueryParams(chatterAccount, chatterNickName, startDate, endDate, page, chatters);
        return this.getSqlSession().selectList(this.getStatement("listChatterRewardInfo"), params);
    }

    @Override
    public Integer getChatterRewardInfoCnt(String chatterAccount, String chatterNickName, Date startDate, Date endDate, List<String> chatters) {
        Map<String, Object> params = setupQueryParams(chatterAccount, chatterNickName, startDate, endDate, null, chatters);
        return this.getSqlSession().selectOne(this.getStatement("getChatterRewardInfoCnt"), params);
    }

    private Map<String, Object> setupQueryParams(String chatterAccount, String chatterName, Date startDate, Date endDate, Page page, List<String> chatters) {
        Map<String, Object> params = Maps.newHashMap();
        if (StringUtils.isNotBlank(chatterAccount)) {
            params.put("chatterAccount", chatterAccount);
        }
        if (StringUtils.isNotBlank(chatterName)) {
            params.put("chatterName", chatterName);
        }
        if (startDate != null && endDate != null) {
            params.put("startDate", startDate);
            params.put("endDate", endDate);
        }
        if (page != null) {
            params.put("page", page);
        }
        if (CollectionUtils.isNotEmpty(chatters)) {
            params.put("chatters", chatters);
        }
        return params;
    }

}